package com.cloudcc.mobile.view.base;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

import com.cloudcc.mobile.R;

public class BaseFragmentActivity extends BaseActivity {

	/**
	 * @Title: getContainerId
	 * @Description: 容器的id
	 * @return int
	 */
	protected int getContainerId() {
		return R.id.container_frag;
	}

	protected final void initMain(Fragment fragment) {
		initMain(fragment, null);
	}

	protected final void initMain(Fragment fragment, Bundle bundle) {
		startFragment(fragment, false, bundle);
	}

	protected final void startFragment(Fragment target, boolean isStack,
			Bundle bundle) {
		if (bundle != null) {
			target.setArguments(bundle);
		}
		FragmentTransaction transaction = this.getSupportFragmentManager()
				.beginTransaction();
		transaction
				.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
				.setCustomAnimations(R.anim.slide_in_from_left,
						R.anim.slide_out_to_right)
				.replace(getContainerId(), target);
		if (isStack) {
			transaction.addToBackStack(target.getClass().getName());
		}
		transaction.commit();

		if (bundle != null) {
			target.setArguments(bundle);
		}
	}

	
	
	
	@Override
	public int getLayoutId() {
		return R.layout.frame_container;
	}
}
